package com.example.imageexample.Main2;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.imageexample.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/30.
 */
public class GridAdapter extends RecyclerView.Adapter<GridAdapter.ViewHolder>  {

    private LayoutInflater inflater;
    private Context mContext;
    private List<String> datas;

    public GridAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        mContext = context;
        datas =new ArrayList<>();
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.layout_image, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(GridAdapter.ViewHolder holder, int position) {
        holder.typeImageLayout.setImageAndType(datas.get(position),2);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public void addAllData(List<String> data) {
        datas.addAll(data);
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private TypeImageLayout typeImageLayout;

        public ViewHolder(View view) {
            super(view);
            typeImageLayout = (TypeImageLayout)view.findViewById(R.id.typeimagelayout);
        }
    }
}
